# -*- coding: utf-8 -*-
import os
import parser

class config:

        def __init__(self):
                self.version     = '0.2'
                self.api_version = 320

                # os.uname() is not available on Windows, so we make this optional.
                try:
                        uname = os.uname()
                        self.os_string = ' (%s %s %s)' % (uname[0], uname[2], uname[4])
                except AttributeError:
                        self.os_string = ''

                self.user_agent = 'Python-iView %s%s' % (self.version, self.os_string)

                self.urls = {}
                self.urls['config_url'] = 'http://www.abc.net.au/iview/xml/config.xml?r=%d' % self.api_version
                self.urls['auth_url']   = 'http://tviview.abc.net.au/iview/auth/?v2' #'http://www2b.abc.net.au/iView/Services/iViewHandshaker.asmx/isp'
                self.urls['series_url'] = 'http://tviview.abc.net.au/iview/api2/?series=%s' #'http://173.230.146.115/iview/api/?series=%s'
                self.urls['view_url']   = 'http://www.abc.net.au/iview/#/program/'
		self.urls['index_url'] = 'http://tviview.abc.net.au/iview/api2/?seriesIndex' #'http://173.230.146.115/iview/api/?seriesIndex'

                self.akamai_playpath_prefix = 'flash/playback/_definst_/'

                # Used for "SWF verification", a stream obfuscation technique
                self.swf_hash    = 'a3eddcc12a96169882f99522a0835e629ae544f2f0bbeb1de4a6ed72754ac965'
                self.swf_size    = '1774'

                self.urls['swf_url']     = 'http://www.abc.net.au/iview/netConnectionWrapper.swf'
                self.page_url    = 'http://www.abc.net.au/iview/'

                # Used for decrypting the obfuscated index.xml file -- uses the RC4 cipher
                self.index_password = 'wallace'

                self.use_encryption = False

                

        def get_config(self, config_xml):
                """	This function fetches the iView "config". Among other things,
                        it tells us an always-metered "fallback" RTMP server, and points
                        us to many of iView's other XML files.
                """

                self.urls.update(parser.parse_config(config_xml))
                print "Config url: " + str(self.urls)
